﻿using System.ComponentModel;
using RaytracerLib;
using RaytracerLib.Attenuations;
using System;
using RaytracerLib.Materials;

namespace Raytracer.PropertyGridDecorators
{
    public class MaterialProperties
    {
        private Material m_material;

        public MaterialProperties(Material a_material)
        {
            m_material = a_material;
        }

        [Category(Categories.PROPERTIES)]
        [TypeConverter(typeof(DoubleConverter))]
        public double Refraction
        {
            get
            {
                return m_material.RefractionIndice;
            }
            set
            {
                m_material.RefractionIndice = value;
            }
        }

        [DisplayName("Attenuation method")]
        [Category(Categories.PROPERTIES)]
        public AttenuationMethod AttenuationMethod
        {
            get
            {
                if (m_material.Attenuation == null)
                    return AttenuationMethod.None;
                else if (m_material.Attenuation is PolynomialAttenuation)
                    return AttenuationMethod.Polynomial;
                else if (m_material.Attenuation is ExponentalAttenuation)
                    return AttenuationMethod.Exponental;
                else
                    throw new InvalidOperationException();
            }
            set
            {
                m_material.Attenuation = RaytracerLib.Attenuations.Attenuation.Create(value);
            }
        }

        [Category(Categories.PROPERTIES)]
        [TypeConverter(typeof(AttenuationConverter))]
        public AttenuationProperties Attenuation
        {
            get
            {
                if (m_material.Attenuation == null)
                    return null;
                else if (m_material.Attenuation is ExponentalAttenuation)
                {
                    return new ExponentalAttenuationProperties(
                        m_material.Attenuation as ExponentalAttenuation);
                }
                else if (m_material.Attenuation is PolynomialAttenuation)
                {
                    return new PolynomialAttenuationProperties(
                        m_material.Attenuation as PolynomialAttenuation);
                }
                else
                    throw new NotImplementedException();
            }
        }
    }
}